package com.tuni.birthdaymoney.web.controller;

import java.security.Principal;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.tuni.birthdaymoney.persistence.entity.QPerson;
import com.tuni.birthdaymoney.service.PersonService;
import com.tuni.birthdaymoney.service.UserService;
import com.tuni.birthdaymoney.web.model.MasterPage;
import com.tuni.birthdaymoney.web.model.StaffManagementPage;

@Controller
public class StaffManagementController {
    @Autowired
    private PersonService personService;
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/staff", method = RequestMethod.GET)
    public String show(Principal principal,
            Map<String, Object> staffManagementPageMap) {
        MasterPage masterPageModel = new MasterPage(userService.getUserByEmail(principal.getName()), false);

        staffManagementPageMap.put("masterPageModel", masterPageModel);

        StaffManagementPage staffManagementPageModel = new StaffManagementPage();
        staffManagementPageModel.setPeople(personService.findAllOrderedByLastName(QPerson.person.fired.isFalse()));
        staffManagementPageMap.put("staffManagementPageModel", staffManagementPageModel);
        return "staff";
    }
}
